<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>新增企业</title>
<link rel="styleSheet" href="../../css/bootstrap.min.css">
<style type="text/css">
	.text{
	width: 300px;
	float:right;
	padding-top: 10px;
	}
	.xianshi{
	margin-left: 100px;
	padding-top: 10px;
	}
	#div{
	margin-left:200px;
	width: 500px;
	}
	.tishi{
	margin-left: 200px;
	}
	#addEnterprise{
	position:absolute;
	top:400px;
	left:760px;
	width: 100px;
	}
</style>
</head>
<body>
	<div id="div">
	<br>
		<form action="../../addCompany.do" method="post" onsubmit="return check()" >
			<input type="hidden" name="user.userRole" value="2">
			<label class="xianshi">企业登录名：</label>
			<input class="text form-control" id="username" onblur="checkUserName()" onfocus="NameMessage()" name="user.userName" type="text" placeholder="企业登录名">
			<br>
			<label id="userNameMessage" class="tishi"></label>
			<br>
			<br>
			<label class="xianshi">企业登录密码：</label>
			<input class="text form-control" id="pwd" onblur="checkUserpwd()" onfocus="pwdMessage()" name="user.userPWD" type="password" placeholder="企业登录密码">
			<br>
			<label id="pwdMessage" class="tishi"></label>
			<br>
			<br>
			<label class="xianshi">企业名称：</label>
			<input class="text form-control" id="name" onblur="checkname()" onfocus="nameMessage()" name="companyName" type="text" placeholder="企业名称">
			<br>
			<label id="nameMessage" class="tishi"></label>
			<br>
			<br>
			<label class="xianshi">企业楼层位置:</label>
			<input class="text form-control" onblur="checkAddress()" id="Address" onfocus="addressMessage()"  name="companyAddress" type="text" placeholder="企业楼层位置">
			<br>
			<label id="addressMessage" class="tishi"></label>
			<br>
			<br>
			<label class="xianshi">企业联系人:</label>
			<input class="text form-control" onblur="checkBoss()" id="boss" onfocus="bossMessage()" name="companyBoss" type="text" placeholder="企业联系人">
			<br>
			<label id="bossMessage" class="tishi"></label>
			<br>
			<br>
			<label class="xianshi">企业联系电话:</label>
			<input maxlength="11" class="text form-control" onblur="checkphone()" id="phone" onfocus="phoneMessage()" name="companyTel" type="text" placeholder="企业联系电话">
			<br>
			<label id="phoneMessage" class="tishi"></label>
			<br>
			<br>
			<input id="addEnterprise" type="submit" class="btn btn-info" value="新增">
		</form>	
	</div>
	<script type="text/javascript" src="../../js/jquery-3.1.0.min.js"></script>
	<script type="text/javascript">
	var a=false;
		function check(){
			var flag=checkUserName()&&checkUserpwd()&&checkname()&&checkAddress()&&checkBoss()&&checkphone()&&a;
			return flag;
		};
		function checkUserName(){
			var username=$("#username").val();
			$.ajax({
				   type: "POST",
				   url: "../../findUserByName.do",
				   data: {"inputName":username},
				   success: function(msg){
				    if(msg!=0){
				    	$("#userNameMessage").html("企业登录名已存在");
				    	a=true;
				    }
				   }
				});
			
			if(username.length==0){
				$("#userNameMessage").html("请输入企业登录名");
				return false;
			}else if(username.length<6||username.length>20){
				$("#userNameMessage").html("企业登录名必须在6-20位之间");
			}else{
				return true;
			}
		};
		function NameMessage(){
			$("#userNameMessage").html("");
		};
		
		function checkUserpwd(){
			var pwd=$("#pwd").val();
			var eReg =  /^[a-zA-Z][a-zA-Z0-9]{5,19}$/;
			if(pwd.length==0){
				$("#pwdMessage").html("请输入企业登录密码");
				return false;
			}else if(!eReg.test(pwd)){
				$("#pwdMessage").html("密码必须以字母开头，且长度为6-20位");
				return false;
			}else{
				return true;
			}
		};
		function pwdMessage(){
			$("#pwdMessage").html("");
		}
		
		function checkname(){
			var name=$("#name").val();
			if(name.length==0){
				$("#nameMessage").html("请输入企业名称");
				return false;
			}else if(name.length<3||name.length>15){
				$("#nameMessage").html("企业名称必须在3-15位之间");
				return false;
			}else{
				return true;
			}
		};
		function nameMessage(){
			$("#nameMessage").html("");
		}
		
		function checkAddress(){
			var address=$("#Address").val();
			if(address.length==0){
				$("#addressMessage").html("请输入企业楼层位置");
				return false;
			}else if(address.length<3||address.length>30){
				$("#addressMessage").html("企业楼层位置必须在3-30位之间");
				return false;
			}else{
				return true;
			}
		};
		function addressMessage(){
			$("#addressMessage").html("");
		}
		
		function checkBoss(){
			var boss=$("#boss").val();
			if(boss.length==0){
				$("#bossMessage").html("请输入企业联系人");
				return false;
			}else if(boss.length<2){
				$("#bossMessage").html("企业联系人名字不能小于2位");
				return false;
			}else{
				return true;
			}
		};
		function bossMessage(){
			$("#bossMessage").html("");
		}
		
		function checkphone(){
			var phone=$("#phone").val();
			var eReg=/^1[34578]\d{9}$/;
			if(phone.length==0){
				$("#phoneMessage").html("电话号码不能为空");
				return false;
			}else if(!eReg.test(phone)){
				$("#phoneMessage").html("电话号码不正确");
				return false;
			}else{
				return true;
			}
		};
		function phoneMessage(){
			$("#phoneMessage").html("");
		}
		
	</script>
</body>
</html>